package ru.ifmo.segal.algorithms;

import java.util.Arrays;
import java.util.List;

/**
 * @author avhaliullin
 */
public class Utils {
    /*
    cb000
    acb00
    0acb0
    00acb
    000ac
     */
    public static List<Double> thomas(List<Double> a, List<Double> b, List<Double> c, List<Double> f) {
        int n = b.size();
        Double[] x = new Double[n];

        for (int i = 1; i < n; i++) {
            double m = a.get(i) / c.get(i - 1);
            c.set(i, c.get(i) - m * b.get(i - 1));
            f.set(i, f.get(i) - m * f.get(i - 1));
        }

        x[n - 1] = f.get(n - 1) / c.get(n - 1);

        for (int i = n - 2; i >= 0; i--) {
            x[i] = (f.get(i) - b.get(i) * x[i + 1]) / c.get(i);
        }
        return Arrays.asList(x);
    }
}
